<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>sessionStorage</title>
</head>
<body>
    <!-- 
        备注：
            1.sessionStorage存储的内容会随着浏览器窗口关闭而消失
            2.localStorage存储的内容需要手动清除才会消失
            3.xxxxxStorage.getItem(xxxx),如果XXXX对应的value获取不到，那么getItem的返回值是null
            4.JSON.parse(null)的结果依然是null
     -->
    <h2>sessionStorage</h2>
    <button onclick="saveData()">点我保存一个数据</button>
    <button onclick="readData()">点我读取一个数据</button>
    <button onclick="deleteData()">点我删除一个数据</button>
    <button onclick="deleteAllData()">点我删除所有数据</button>
    <script>
        let p={name:'zx',age:18}
        function saveData(){
            sessionStorage.setItem('msg','hello!!')
            sessionStorage.setItem('msg2',666)
            sessionStorage.setItem('person',JSON.stringify(p))
        }
        function readData(){
            console.log(sessionStorage.getItem('msg'));
            console.log(sessionStorage.getItem('msg2'));
            let result=sessionStorage.getItem('person')
            console.log(JSON.parse(result));
        }
        function deleteData(){
            sessionStorage.removeItem('msg')
        }
        function deleteAllData(){
            sessionStorage.clear()
        }
    </script>
</body>
</html>